package com.vibration.web.controller.baseinfo;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import ComputeMoreTemTwo.computeMoreTemTwo;
import ComputeXiEnd.computeXiEnd;
import com.mathworks.toolbox.javabuilder.MWClassID;
import com.mathworks.toolbox.javabuilder.MWNumericArray;
import com.vibration.baseinfo.domain.CzGroundWaterData;
import com.vibration.baseinfo.domain.CzGroundWaterResult;
import com.vibration.baseinfo.service.ICzGroundWaterDataService;
import com.vibration.baseinfo.service.ICzGroundWaterResultService;
import com.vibration.framework.config.ServerConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vibration.common.annotation.Log;
import com.vibration.common.core.controller.BaseController;
import com.vibration.common.core.domain.AjaxResult;
import com.vibration.common.enums.BusinessType;
import com.vibration.baseinfo.domain.CzGroundWaterRecord;
import com.vibration.baseinfo.service.ICzGroundWaterRecordService;
import com.vibration.common.utils.poi.ExcelUtil;
import com.vibration.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 水脉分析记录Controller
 * 
 * @author Mr_wu
 * @date 2023-03-20
 */
@RestController
@RequestMapping("/baseinfo/waterRecord")
public class CzGroundWaterRecordController extends BaseController
{
    @Autowired
    private ICzGroundWaterRecordService czGroundWaterRecordService;

    @Autowired
    private ICzGroundWaterDataService czGroundWaterDataService;

    @Autowired
    private ICzGroundWaterResultService czGroundWaterResultService;

    @Autowired
    private ServerConfig serverConfig;

    /**
     * 查询水脉分析记录列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:waterRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzGroundWaterRecord czGroundWaterRecord)
    {
        startPage();
        List<CzGroundWaterRecord> list = czGroundWaterRecordService.selectCzGroundWaterRecordList(czGroundWaterRecord);
        return getDataTable(list);
    }

    /**
     * 导出水脉分析记录列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:waterRecord:export')")
    @Log(title = "水脉分析记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzGroundWaterRecord czGroundWaterRecord)
    {
        List<CzGroundWaterRecord> list = czGroundWaterRecordService.selectCzGroundWaterRecordList(czGroundWaterRecord);
        ExcelUtil<CzGroundWaterRecord> util = new ExcelUtil<CzGroundWaterRecord>(CzGroundWaterRecord.class);
        util.exportExcel(response, list, "水脉分析记录数据");
    }

    /**
     * 获取水脉分析记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:waterRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(czGroundWaterRecordService.selectCzGroundWaterRecordById(id));
    }

    /**
     * 新增水脉分析记录
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:waterRecord:add')")
    @Log(title = "水脉分析记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzGroundWaterRecord czGroundWaterRecord)
    {
        String username=getUsername();
        if(StringUtils.isEmpty(czGroundWaterRecord.getCreatedBy())){
            czGroundWaterRecord.setCreatedBy(username);
        }
        if(StringUtils.isEmpty(czGroundWaterRecord.getUpdatedBy())){
            czGroundWaterRecord.setUpdatedBy(username);
        }
        return toAjax(czGroundWaterRecordService.insertCzGroundWaterRecord(czGroundWaterRecord));
    }

    /**
     * 水脉分析计算
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:waterRecord:edit')")
    @Log(title = "水脉分析记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzGroundWaterRecord czGroundWaterRecord)throws Exception
    {
        return toAjax(czGroundWaterRecordService.updateCzGroundWaterRecord(czGroundWaterRecord));
    }

    /**
     * 删除水脉分析记录
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:waterRecord:remove')")
    @Log(title = "水脉分析记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        //删除data数据
        czGroundWaterDataService.deleteCzGroundWaterDataByRecordIds(ids);
        //删除result数据
        czGroundWaterResultService.deleteCzGroundWaterResultByRecordIds(ids);
        return toAjax(czGroundWaterRecordService.deleteCzGroundWaterRecordByIds(ids));
    }

    /**
     * 导入地下水脉数据
     */
    @PostMapping("/importData")
    public AjaxResult importStudent(MultipartFile file,CzGroundWaterRecord czGroundWaterRecord) throws Exception
    {
        String setfileName=file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf("."));
        czGroundWaterRecord.setRecordName(setfileName);
        czGroundWaterRecord.setCreatedBy(getUsername());
        czGroundWaterRecord.setFilePath(serverConfig.getUrl());
        CzGroundWaterRecord czGroundWaterRecord1 = czGroundWaterRecordService.importWaterData(file,czGroundWaterRecord);
        return AjaxResult.success(czGroundWaterRecord1);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<CzGroundWaterData> util = new ExcelUtil<CzGroundWaterData>(CzGroundWaterData.class);
        util.importTemplateExcel(response, "温度数据");
    }







}
